package co.fitstart.mobile.handler.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.demo2do.core.support.Result;

import co.fitstart.entity.coupon.Coupon;
import co.fitstart.entity.order.Order;
import co.fitstart.entity.user.User;
import co.fitstart.mobile.handler.ActivateHandler;
import co.fitstart.mobile.service.CouponService;

@Component("activateHandlerImpl")
public class ActivateHandlerImpl implements ActivateHandler{
    
    @Autowired
    private CouponService couponService;
    
    private static final Logger logger = LoggerFactory.getLogger(ActivateHandlerImpl.class);

    /*
     * (non-Javadoc)
     * @see co.fitstart.mobile.handler.ActivateHandler#activateCoupon(co.fitstart.entity.coupon.Coupon, co.fitstart.entity.user.User, java.lang.Long)
     */
    public Result activateCoupon(Coupon coupon, User user, Long siteId) {
        logger.trace("activateCoupon() create order first");
        Order order = couponService.createOrder(coupon, user, siteId);
        Result result = new Result();
        if (order != null) {
            logger.trace("activateCoupon() pay order");
            result = couponService.payOrder(order,coupon);
        }
        return result;
    }
    
    

}
